import React, { useRef, useEffect } from 'react';
import { PageContainer } from '@ant-design/pro-layout';
import ReactEcharts from 'echarts-for-react';

export default () => {
  const instance = useRef(null);
  const lineOption = () => {
    const option = {
      xAxis: {
        type: 'category',
        data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
      },
      yAxis: {
        type: 'value',
      },
      series: [
        {
          data: [120, 200, 150, 80, 70, 110, 130],
          type: 'bar',
          showBackground: true,
          backgroundStyle: {
            color: 'rgba(180, 180, 180, 0.2)',
          },
        },
      ],
    };
    return option;
  };
  const onChartClick = (param, echarts) => {
    console.log(param, echarts);
  };
  const onChartLegendselectchanged = (param, echarts) => {
    console.log(param, echarts);
  };
  //   const resize = () => {
  //     instance.current && instance.current.echarts.resize();
  //   };
  useEffect(() => {
    console.log(instance.current);

    // window.addEventListener('resize', instance.current.echarts.resize());
  }, []);
  return (
    <PageContainer>
      <ReactEcharts
        ref={instance}
        option={lineOption()}
        onEvents={{
          click: onChartClick,
          mousedown: onChartClick,
          legendselectchanged: onChartLegendselectchanged,
        }}
      ></ReactEcharts>
    </PageContainer>
  );
};
